<?php

namespace Modules\Goods\Http\Controllers\API;

use Illuminate\Http\Request;
use Modules\Goods\Entities\Goods;
use Illuminate\Routing\Controller;
use Modules\Goods\Services\GoodsService;

class GoodsController extends Controller
{
    /**
     * 获取商品详情
     * @param int $id
     * @return Goods
     */
    public function show(int $id)
    {
        return Goods::with('skus')->find($id);
    }

    /**
     * 搜索商品
     *
     * @param string $word
     * @return Collection
     */
    public function search(Request $request, GoodsService $sGoods)
    {
        $word = $request->word;

        $query = Goods::where('name', 'like','%'.$word.'%')
            ->orWhere('keyword','like','%'.$word.'%')
            ->orWhere('brand','like','%'.$word.'%')
            ->orderBy('category_id');

        return $sGoods->getGoodsBaseInfoPaginate($query);
    }

}
